
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Synchronized锁的膨胀升级过程 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Synchronized锁的膨胀升级过程 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Java `synchronized` 锁的膨胀升级过程包含哪几个主要状态？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">锁的膨胀升级过程涉及从无锁状态开始，逐步升级为偏向锁、轻量级锁，最后到重量级锁。</div>
          </div>
          <div class="card-source">来源: 文档开篇及各级锁标题</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">偏向锁（Biased Locking）的主要目的是什么？它如何实现这一目的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">偏向锁的目的是在无竞争的情况下，减少加锁和解锁的开销。它通过在对象 Mark Word 中记录获取锁的线程ID来实现，当同一线程再次进入同步代码块时，无需执行任何加锁操作。</div>
          </div>
          <div class="card-source">来源: 文档中「2. 偏向锁 (Biased Locking)」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么情况下偏向锁会升级为轻量级锁（Lightweight Locking）？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当另一个线程尝试获取一个已经被偏向锁占有的锁时，JVM会撤销偏向锁，并将锁升级为轻量级锁。</div>
          </div>
          <div class="card-source">来源: 文档中「3. 轻量级锁 (Lightweight Locking)」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">轻量级锁是如何处理锁竞争的？它适用于什么场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">轻量级锁采用自旋的方式进行锁竞争，线程通过CAS操作尝试获取锁。它适用于线程竞争较少的场景，旨在通过自旋减少线程阻塞来提升性能。</div>
          </div>
          <div class="card-source">来源: 文档中「3. 轻量级锁 (Lightweight Locking)」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">从轻量级锁升级为重量级锁（Heavyweight Locking）的条件是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当多个线程争抢同一把锁，并且通过自旋的方式也无法解决竞争问题时，轻量级锁就会升级为重量级锁。</div>
          </div>
          <div class="card-source">来源: 文档中「4. 重量级锁 (Heavyweight Locking)」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">重量级锁依赖什么底层机制来管理线程，这会带来什么性能开销？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">重量级锁通过操作系统的互斥锁机制（Monitor对象）来管理线程的阻塞与唤醒。这种操作需要由操作系统内核完成，会导致线程的上下文切换，从而增加系统的性能开销。</div>
          </div>
          <div class="card-source">来源: 文档中「4. 重量级锁 (Heavyweight Locking)」和「5. 锁膨胀的影响」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">synchronized 锁一旦升级为重量级锁，是否还能降级回轻量级锁或偏向锁？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">不可以。一旦锁升级为重量级锁，JVM不会将其降级，即使后续的竞争减少，锁的状态也不会改变。</div>
          </div>
          <div class="card-source">来源: 文档中「5. 锁膨胀的影响」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">为了避免不必要的锁膨胀，文档中提到了哪两种优化策略？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 优化锁的粒度：尽量减少同步代码块的范围以降低锁竞争。 2. 选择合适的锁机制：在高并发场景下，可以考虑使用像 ReentrantLock 这样更灵活的锁机制。</div>
          </div>
          <div class="card-source">来源: 文档中「6. 如何避免锁膨胀」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在64位JVM中，对象的Mark Word在无锁状态下存储了哪些信息？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在无锁状态下，64位JVM中对象的Mark Word存储了对象的HashCode、GC信息以及锁标志位等内容。</div>
          </div>
          <div class="card-source">来源: 文档中「1. 无锁状态」部分</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
